﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using System.Linq;
using DAO;
using BUS;

namespace project
{
    public partial class docgia : DevComponents.DotNetBar.RibbonForm
    {
        DOCGIA dg;
        KhachHangBUS dgBUS = new KhachHangBUS();
        public docgia(DOCGIA _dg)
        {
            dg = _dg;
            InitializeComponent();
            
        }
       

        private void docgia_Load(object sender, EventArgs e)
        {

            loadthongtindocgia();
            loadphieumuon();
            loadtheloai();
            loadphieutra();
                     
        }
        public void loadtheloai()
        {
            List<LOAISACH> l = new List<LOAISACH>();
            l = dgBUS.loadloaisach();
            cbxTheLoai.DataSource = l;
            cbxTheLoai.ValueMember = "MA_LOAI";
            cbxTheLoai.DisplayMember = "TEN_LOAI";
        }
        public void loadphieumuon()
        {
            string ma = dg.MA_DOC_GIA;
            //List<PHIEUMUON> l = new List<PHIEUMUON>();
            var l = dgBUS.loadphieumuondocgia(ma);
           // Doc = dgBUS.loadphieumuondocgia(ma);
           
            dgvphieumuon.DataSource = l;
        }
        public void loadphieutra()
        {
            string ma = dg.MA_DOC_GIA;
            //List<PHIEUMUON> l = new List<PHIEUMUON>();
            var l = dgBUS.loadphieutradocgia(ma);
            // Doc = dgBUS.loadphieumuondocgia(ma);

            gvphieutra.DataSource = l;
        }
        public void loadthongtindocgia()
        {

            txtHoTen.Text = dg.TEN_DOC_GIA;
            txtmadocgia.Text = dg.MA_DOC_GIA;
            txtngaylap.Text = dg.NGAY_LAP_THE.ToString();
            txtngayhethan.Text = dg.NGAY_HET_HAN.ToString();
            txtNamSinh.Text = dg.NGAY_SINH.ToString();
            txtDiaChi.Text = dg.DIA_CHI;
            txtPhone.Text = dg.SDT;
            if (dg.LOAI_DOC_GIA == 1)
            {
                txtLoaiDocGia.Text = "Người Lớn";
            }
            else
            {
                txtLoaiDocGia.Text = "Trẻ Em";
            }

        }
        private void ButtonItem10_Click(object sender, EventArgs e)
        {

            tabXemThongTin.ShowSubItems=true;
        }

        private void ButtonItem9_Click(object sender, EventArgs e)
        {
           
        }

        private void ButtonItem8_Click(object sender, EventArgs e)
        {
            superTabItem7.Visible = true;
        }

        private void txtThuXinNghiChiTiet_TextChanged(object sender, EventArgs e)
        {

        }

        private void GroupPanel24_Click(object sender, EventArgs e)
        {

        }

        private void btnCapNhat_Click(object sender, EventArgs e)
        {
            
            string mkc = txtcu.Text;
            string mkm = txtMoi.Text;
            string mknl = txtnhaplai.Text;
            string kq = dgBUS.CapNhatMatKhau(mkc, mkm, mknl, dg);
            MessageBox.Show(kq);
            if (kq == "Cap nhat thanh cong.")
            {
                txtcu.Text = "";
                txtMoi.Text = "";
                txtnhaplai.Text = "";
            }
        }

        private void dgvphieumuon_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            int ma = int.Parse(dgvphieumuon.CurrentRow.Cells[0].Value.ToString());
            var l = dgBUS.loadchitietphieu(ma);
            // Doc = dgBUS.loadphieumuondocgia(ma);

            dgvdanhsachsachmuon.DataSource = l;
        }

        private void btnReset_Click(object sender, EventArgs e)
        {
            txtTen.Text = "";
            txtTacGia.Text = "";
        }

        private void btnTimKiem_Click(object sender, EventArgs e)
        {
            int maloai = int.Parse(cbxTheLoai.SelectedValue.ToString());
            string ten = txtTen.Text;
            string tacgia = txtTacGia.Text;
            var ds = dgBUS.timkiemsach(ten, tacgia, maloai);
            gvSach.DataSource = ds;
        }

        private void gvphieutra_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            int ma = int.Parse(gvphieutra.CurrentRow.Cells[0].Value.ToString());
            var l = dgBUS.loadchitietphieutra(ma);
            // Doc = dgBUS.loadphieumuondocgia(ma);

            gvchitietphieutra.DataSource = l;
        }

        private void dgvphieumuon_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

    

       
       
    }
}